<?php
class UserRoleModel extends Model{
    protected $table = 'user_role';
    public function getByUser(){
        $role_id = Request::asget(3,'id');
        if(false === $role_id){
            exit;
        }else{
            return $this->where(['role_id'=>$role_id])->one();
        }
    }
    public function up($id){
        $names = [
            'role_name'=>6,
            'role_description'=>6,
        ];
        $rule_ids = $_POST['rule_id'];
        $rule_ids = Request::val($rule_ids,0);
        $data = Request::batch(1,$names);
        $data['role_rules'] = serialize($rule_ids);

        return $this->where(['role_id'=>$id])->update($data);
    }    
    public function add(){
        $names = [
            'role_name'=>6,
            'role_description'=>6,
        ];
        $rule_ids = $_POST['rule_id'];
        $rule_ids = Request::val($rule_ids,0);
        $data = Request::batch(1,$names);
        $data['role_rules'] = serialize($rule_ids);
        return $this->insert($data);
    }    
}